package com.fengdi.everyday.easy;

import java.util.ArrayList;
import java.util.Objects;

public class HasSameDigits {
    public boolean hasSameDigits(String s) {
        ArrayList<Integer> list = new ArrayList<>();
        for(char c : s.toCharArray()) {
            list.add(c - '0');
        }

        for(int i = list.size() - 1; i >= 2; i--) {
            for(int j = 1; j <= i; j++) {
                int x = this.calculate(list.get(j), list.get(j - 1));
                list.set(j - 1, x);
            }
        }

        return Objects.equals(list.get(0), list.get(1));
    }

    private int calculate(Integer x, Integer y){
        return (x + y) % 10;
    }
}
